﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Sitecore.Data.Items;
using System.Data;
using Workflow.Alerts.DAL;
using Workflow.Alerts.Interfaces.ProfileSettings;

namespace Workflow.Alerts
{
    public class ContractorListPresenter : Presenter
    {
        #region members
        private readonly ContractorDAL model;
        private readonly IContractorListView view;
        #endregion

        #region constructor
        public ContractorListPresenter(IContractorListView _view)
            : this(_view, null)
        { }

        public ContractorListPresenter(IContractorListView _view, ISessionProvider session)
            : base(_view, session)
        {
            view = base.GetView<IContractorListView>();
            view.OnPageLoad += view_OnLoad;
            model = new ContractorDAL();
        }

        #endregion

        #region private methods

        private void view_OnLoad()
        {   
            var filter = new WorkflowFilter
            {
                MunicipalityId = CurrentUser.TypeId//CurrentUser.MunicipalityId
            };

            var filterSql = new WorkflowFilterSql(filter);

            DataTable operators = model.GetContractorList(filterSql);

            view.Contractors = operators;
        }

        #endregion
    }
}
